package com.jxdinfo.hussar.cloud.module.example.lift.controller;



import cn.hutool.db.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jxdinfo.hussar.cloud.module.example.lift.dto.LiftHistoryCountDto;
import com.jxdinfo.hussar.cloud.module.example.lift.dto.LiftHistoryCountLineDto;
import com.jxdinfo.hussar.cloud.module.example.lift.dto.LiftHistoryCountSearchDto;
import com.jxdinfo.hussar.cloud.module.example.lift.model.LiftHistoryCount;
import com.jxdinfo.hussar.cloud.module.example.lift.service.LiftHistoryCountService;
import com.jxdinfo.hussar.platform.core.base.apiresult.ApiResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 升降机历史统计(LiftHistoryCount)表控制层
 *
 * @author makejava
 * @since 2023-10-23 18:26:21
 */
@RestController
@RequestMapping("LiftHistoryCountApi")
public class LiftHistoryCountController  {
    /**
     * 服务对象
     */
    @Resource
    private LiftHistoryCountService liftHistoryCountService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param liftHistoryCount 查询实体
     * @return 所有数据
     */
    @GetMapping
    public ApiResponse selectAll(Page<LiftHistoryCount> page, LiftHistoryCount liftHistoryCount) {
        return ApiResponse.success(this.liftHistoryCountService.page(page, new QueryWrapper<>(liftHistoryCount)));
    }

    public ApiResponse<Page<LiftHistoryCount>> findByPage(LiftHistoryCountSearchDto liftHistoryCountSearchDto) {

        liftHistoryCountSearchDto.setTyProjectCode("ProjectUtil.getProjectInfo().getProjectCode()");

        Page<LiftHistoryCount> pageResult = liftHistoryCountService.findPage(liftHistoryCountSearchDto);
       // ResultData<PageResult<LiftHistoryCountDto>> result = this.convertToDtoPageResult(pageResult);
        return ApiResponse.success(pageResult);
    }
    /**
     * 升降机功效分析折线图表
     * @param liftHistoryCountSearchDto
     * @return
     */
    @PostMapping("/findByLine")
    public ApiResponse<List<LiftHistoryCountLineDto>> findByLine(LiftHistoryCountSearchDto liftHistoryCountSearchDto) {
        if (liftHistoryCountSearchDto == null){
            return null;
        }

        if(ObjectUtils.isNotEmpty(liftHistoryCountSearchDto.getTyProjectCode())){
            liftHistoryCountSearchDto.setTyProjectCode(liftHistoryCountSearchDto.getTyProjectCode());
        }else{
            //liftHistoryCountSearchDto.setTyProjectCode(ProjectUtil.getProjectInfo().getProjectCode());
        }

        return ApiResponse.success(liftHistoryCountService.findByLine(liftHistoryCountSearchDto));
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ApiResponse selectOne(@PathVariable Serializable id) {
        return ApiResponse.success(this.liftHistoryCountService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param liftHistoryCount 实体对象
     * @return 新增结果
     */
    @PostMapping
    public ApiResponse insert(@RequestBody LiftHistoryCount liftHistoryCount) {
        return ApiResponse.success(this.liftHistoryCountService.save(liftHistoryCount));
    }

    /**
     * 修改数据
     *
     * @param liftHistoryCount 实体对象
     * @return 修改结果
     */
    @PutMapping
    public ApiResponse update(@RequestBody LiftHistoryCount liftHistoryCount) {
        return ApiResponse.success(this.liftHistoryCountService.updateById(liftHistoryCount));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public ApiResponse delete(@RequestParam("idList") List<Long> idList) {
        return ApiResponse.success(this.liftHistoryCountService.removeByIds(idList));
    }
}

